package sort;

import java.util.Arrays;

public class CountingSort {

    private static final int[] array = {4, 3, 5, 2, 6, 0, 1, 2, 7, 3};

    public static void main(String[] args) {
        countingSort();
    }

    private static void countingSort() {
        int[] tempArray = new int[8];
        for (int a : array) {
            tempArray[a] += 1;
        }

        for (int i = 0; i < tempArray.length - 1; i++) {
            tempArray[i + 1] += tempArray[i];
        }
        System.out.println(Arrays.toString(tempArray));

        int[] sortedArray = new int[array.length];

        for (int i = 0; i < array.length; i++) {
            sortedArray[tempArray[array[i]] - 1] = array[i];
            tempArray[array[i]]--;
        }
        System.out.println(Arrays.toString(sortedArray));
    }
}
